<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 图片分类管理 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-button type="primary" icon="el-icon-lx-add" class="handle-del mr10" @click="addUserFormShow">新增图片分类 </el-button>
                <el-button type="primary" class="handle-del mr10" @click="getUserList">刷新 </el-button>
            </div>
            <el-table
                :data="userList"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column prop="name" label="分类名称" align="center" width="160"></el-table-column>
                <el-table-column prop="description" label="描述" align="center" width="160"></el-table-column>
                <el-table-column label="头像" align="center">
                    <template slot-scope="scope">
                        <el-form label-position="left" inline class="demo-table-expand">
                            <el-form-item>
                                <div class="demo-image__preview">
                                    <el-image style="width: 100px; height: 100px" :src="scope.row.icon"> </el-image>
                                </div>
                            </el-form-item>
                        </el-form>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="180" align="center" fixed="right">
                    <template slot-scope="scope">
                        <el-button class="green" @click="viewUserDetailInfo(scope.row)">编辑 </el-button>
                        <el-button class="green" @click="deleteItem(scope.row)">删除 </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- <div class="pagination">
                <el-pagination
                    background
                    layout="total,sizes, prev, pager, next, jumper"
                    @size-change="handlePageSizeChange"
                    @current-change="handlePageChange"
                    :current-page="query.pageCurrent"
                    :page-sizes="[10, 50, 100, 200, 500, 1000]"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                >
                </el-pagination>
            </div> -->
        </div>
    </div>
</template>

<script>
import { imgSortPhotoListByTag, deleteUser, deleteTag } from '../../../utils';

export default {
    name: 'basetable',
    data() {
        return {
            query: {
                pageCurrent: 1,
                pageSize: 10,
                userName: '',
                idList: []
            },
            //上次登录时间与地址
            userList: [],
            pageTotal: 0
        };
    },
    created() {
        this.getUserList();
    },
    methods: {
        //获取用户列表
        getUserList() {
            imgSortPhotoListByTag().then(res => {
                let data = res.data.data;
                // this.pageTotal = data.data.total;
                this.userList = data;
            });
        },
        // 多选操作
        handleSelectionChange(val) {
            let idList = [];
            val.forEach(function(item) {
                idList.push(item.id);
            });
            this.query.idList = idList;
        },
        //删除操作
        delAllSelection() {
            if (this.query.idList.length === 0) {
                this.$message.warning('请勾选数据');
            } else {
                deleteUser(this.query).then(res => {
                    this.$message.success(res.data.msg);
                    this.getUserList();
                });
            }
        },
        //分页跳转
        handlePageChange(val) {
            this.$set(this.query, 'pageCurrent', val);
            this.getUserList();
        },
        //每页大小改变
        handlePageSizeChange(val) {
            this.$set(this.query, 'pageSize', val);
            this.getUserList();
        },
        //真实姓名
        handleSearchRealName(val) {
            this.$set(this.query, 'userName', val);
            this.getUserList();
        },
        //修改用户信息
        viewUserDetailInfo(id) {
            this.$router.push('/imgUser?update=' + JSON.stringify(id));
        },
        addUserFormShow() {
            this.$router.push('/imgUser');
        },
        deleteItem(item) {
          console.log(item);
          deleteTag(item.id).then(res => {
            console.log('res', res);
            if (res.data.code === 200) {
              this.$message.success('删除成功');
              this.getUserList()
              this.query.pageCurrent = 1
            } else {
              this.$message.success(res.data.msg);
              this.getUserList()
              this.query.pageCurrent = 1
            }
          })
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}

.table {
    width: 100%;
    font-size: 14px;
}

.red {
    color: #ff0000;
}

.mr10 {
    margin-right: 10px;
}
</style>
